package com.zy.springboot.dao.system;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.zy.springboot.dao.BaseDao;
import com.zy.springboot.entity.IBaseEntity;
import com.zy.springboot.entity.user.UserEntity;
import com.zy.springboot.entity.user.YzmEntity;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by y on 2019/1/11.
 */
@Repository
public class YzmDao extends BaseDao {

    public YzmDao(){
        super.iBaseEntity = new YzmEntity();
    }

    @Override
    public IBaseEntity convertJson2Entity(JSONObject json) {
        return JSON.toJavaObject(json,YzmEntity.class);
    }

    public JSONObject checkAndYzm(String tel){
        StringBuffer sql=new StringBuffer();
        sql.append(" SELECT yzm,TIMESTAMPDIFF(SECOND,(select CREATE_TIME from t_sys_yzm WHERE tel =? ORDER BY CREATE_TIME desc limit 0,1),NOW()) as second FROM t_sys_yzm");
        sql.append(" WHERE tel =?");
        sql.append(" ORDER BY CREATE_TIME DESC LIMIT 0,1");
        return super.queryForJsonObject(sql.toString(),new Object[]{tel,tel});
    }
}
